<?php

Route::group(['middleware' => ['apiException', 'toNull']], function () {
    //  token 获取
    Route::post('auth/token', 'Api\Token\TokenController@issue')->name('api.auth.token')->middleware('rongToken');
    //  使用原有token 刷新token
    Route::post('auth/token/refresh', 'Api\Token\TokenController@refresh')
        ->name('api.auth.token.refresh')->middleware('auth:api_user');

    Route::get('user/info', 'UserInfoController@getUserInfo')->name('api.user.info');

    Route::group(['prefix' => 'bloodGlucose'], function () {
        Route::get('bloodTest/statistics', 'Dynamic\BloodTestController@getStatisticsList')->name('api.bloodGlucose.bloodTest.statistics');
        Route::post('bloodContrast/store', 'Dynamic\BloodGlucoseContrastController@store')->name('bloodContrast.store');
        Route::get('bloodContrast/getList', 'Dynamic\BloodGlucoseContrastController@getList')->name('bloodContrast.getList');

    });

    Route::group(['middleware' => ['auth:api_patient']], function () {

        //  创建病历
        Route::group(['prefix' => 'record'], function () {
            //  首诊创建
            Route::post('store', 'Api\Record\RecordController@store')->name('api.record.store');
            //  既往史及主诉组合存储
            Route::post('initial', 'Api\Record\RecordController@fillInitial')->name('api.record.initial');
        });
        //  新创建病历
        Route::group(['prefix' => 'record'], function () {
            //  首诊创建
            Route::post('new/store', 'Api\Record\MedicalRecordController@store')->name('api.new.record.store');
            Route::post('/new/delete', 'Api\Record\MedicalRecordController@delete')->name('api.new.record.delete');
            Route::get('/new/getList', 'Api\Record\MedicalRecordController@getListByHospital')->name('api.new.record.getList');
            Route::post('/new/subsequent', 'Api\Record\MedicalRecordController@subsequent')->name('api.new.record.subsequent');
            //  既往史及主诉组合存储
            Route::post('new/initial', 'Api\Record\MedicalRecordController@fillInitial')->name('api.new.record.initial');
        });

        //  主诉
        Route::group(['prefix' => 'complaint'], function () {
            //  首诊
            Route::post('store', 'Manage\ComplaintController@store')->name('api.complaint.store');
            Route::get('show', 'Api\Record\ComplaintController@show')->name('api.complaint.edit');
            Route::post('update', 'Manage\ComplaintController@update')->name('api.complaint.update');

            //  复诊
            Route::post('follow/store', 'Api\Hpi\HpiSubController@store')->name('api.hpiSub.store');
            Route::get('follow/show', 'Api\Hpi\HpiSubController@edit')->name('api.hpiSub.edit');
            Route::post('follow/update', 'Manage\HpiSubController@update')->name('api.hpiSub.update');
        });
        //  主诉

        //  创建复诊
        Route::post('/record/subsequent', 'Api\Record\RecordController@subsequent')->name('api.record.subsequent');

        //  复诊主诉(属于复诊的随诊组)
        //  创建病历

        //  病历删除
        Route::post('/record/delete', 'Api\Record\RecordController@delete')->name('api.record.delete');
        //  病历删除结束

        //  患者
        Route::group(['prefix' => 'patient'], function () {
            Route::get('info', 'Api\Patient\PatientController@info')->name('api.patient.info');
            Route::get('record/list', 'Api\Patient\PatientController@recordList')->name('api.patient.record.list');
        });


        //首诊
//        Route::group(['prefix' => 'subsequent/drug'], function () {
//            Route::post('store', 'Api\Record\DrugController@firstStore')->name('api.hpiSub.store');
//            Route::get('show', 'Api\Record\DrugController@firstShow')->name('api.hpiSub.subShow');
//            Route::post('update', 'Api\Record\DrugController@firstUpdate')->name('api.hpiSub.update');
//        });
        //复诊
        Route::group(['prefix' => 'subsequent/drug'], function () {
            Route::post('store', 'Api\Record\DrugController@subsequent')->name('api.hpiSub.store');
            Route::get('show', 'Api\Record\DrugController@subShow')->name('api.hpiSub.subShow');
            Route::post('update', 'Api\Record\DrugController@subUpdate')->name('api.hpiSub.update');
        });
        //  药物添加 更新 获取结束
        Route::group(['middleware' => ['ValidateUser']], function () {
            //  既往史
            Route::group(['prefix' => 'past'], function () {
                Route::post('store', 'Manage\PastHistoryController@store')->name('api.past.store');
                Route::get('show', 'Manage\PastHistoryController@edit')->name('api.past.edit');
                Route::post('update', 'Manage\PastHistoryController@update')->name('api.past.update');
            });
            //  既往史结束
            //++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //  家族史
            Route::group(['prefix' => 'family'], function () {
                Route::post('store', 'Manage\FamilyHistoryController@store')->name('family.store');
                Route::get('edit', 'Manage\FamilyHistoryController@edit')->name('family.edit');
                Route::post('update', 'Manage\FamilyHistoryController@update')->name('family.update');
            });
            //  个人史
            Route::group(['prefix' => 'person'], function () {
                Route::post('store', 'Manage\PersonalHistoryController@store')->name('person.store');
                Route::get('edit', 'Manage\PersonalHistoryController@edit')->name('person.edit');
                Route::post('update', 'Manage\PersonalHistoryController@update')->name('person.update');
            });
            //  个人史结束

            //  月经婚育史项目
            Route::group(['prefix' => 'marriage'], function () {
                Route::post('store', 'Manage\MarriageHistoryController@store')->name('marriage.store');
                Route::get('edit', 'Manage\MarriageHistoryController@edit')->name('marriage.edit');
                Route::post('update', 'Manage\MarriageHistoryController@update')->name('marriage.update');
            });
            //  月经婚育史项目结束
            //++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //  辅助检查项目
            Route::group(['prefix' => 'auxiliary'], function () {
                Route::post('store', 'Api\Record\AuxiliaryController@store')->name('api.auxiliary.store');
                Route::get('show', 'Api\Record\AuxiliaryController@edit')->name('api.auxiliary.edit');
                Route::post('update', 'Api\Record\AuxiliaryController@update')->name('api.auxiliary.update');
            });
            //  辅助检查项目结束
        });
        //  药物
        Route::group(['prefix' => 'drug'], function () {
            //  获取药物分组
            Route::get('group', 'Manage\DrugController@group')->name('api.drug.group');
            Route::get('list', 'Manage\DrugController@index')->name('api.drug.list');

            Route::get('record', 'Manage\DrugController@drugsOfRecord')->name('api.drug.record');
        });

        //  药物结束

        //  症状列表
        Route::get('symptom/list', 'Manage\SymptomController@index')->name('api.symptom.list');

        //  医生病历绑定
        Route::post('doctor/bind', 'Api\Doctor\DoctorController@bind')->name('api.doctor.bind');
        //  医生病历绑定

        //  病历打印 页面
        Route::get('print/show', 'Manage\PrintController@show')->name('api.record.print.show');
    });

    Route::group(['middleware' => ['auth:api_doctor']], function () {
        //  医生获取患者的信息
        Route::group(['prefix' => 'doctor'], function () {
            Route::get('patient/records', 'Api\Patient\PatientController@recordList');
            Route::get('new/patient/records', 'Api\Record\MedicalRecordController@getListByDoctorHospitalId');
            Route::get('print/show', 'Manage\PrintController@show')->middleware('scene');
        });

        //医生获取所属医院  所有患者
        Route::group(['prefix' => 'doctor'], function () {
            Route::get('patient/list', 'Api\Patient\PatientController@patientList');
            Route::get('hospital/list', 'Api\Patient\PatientController@hospitalList');
            Route::get('doctor/list', 'Api\Patient\PatientController@doctorList');
        });


        //群组
        Route::group(['prefix' => 'group'], function () {
            //  创建群组
            Route::post('store', 'Api\Doctor\UserGroupController@store')->name('api.group.store');
            //  解散群组
            Route::delete('delete', 'Api\Doctor\UserGroupController@delete')->name('api.group.delete');
            //  我的群组
            Route::get('list', 'Api\Doctor\UserGroupController@getList')->name('api.group.list');
            //  修改群组内容
            Route::post('update', 'Api\Doctor\UserGroupController@update')->name('api.group.update');
            //获取群成员
            Route::get('member/list', 'Api\Doctor\UserGroupMemberController@getGroupMemberList')->name('api.group.member.getList');
            //加入群组
            Route::post('member/store', 'Api\Doctor\UserGroupMemberController@store')->name('api.group.member.store');
            //群组信息
            Route::get('show', 'Api\Doctor\UserGroupController@show')->name('api.group.info');
            //生成加入群组二维码
            Route::post('insert/qrcode', 'Api\Doctor\UserGroupController@createInsertQrCode')->name('api.group.qrcode');
            //退去该群
            Route::delete('member/delete', 'Api\Doctor\UserGroupMemberController@delete')->name('api.group.member.delete');

        });
        //好友关系
        Route::group(['prefix' => 'friends'], function () {
            //  创建好友
            Route::post('store', 'Api\UserFriends\UserFriendsController@store')->name('api.friends.store');
            //  删除好友
            Route::delete('delete', 'Api\UserFriends\UserFriendsController@delete')->name('api.friends.delete');
            //  获取好友列表
            Route::get('list', 'Api\UserFriends\UserFriendsController@getList')->name('api.friends.list');
            //  返回是否为好友
            Route::get('isFriend', 'Api\UserFriends\UserFriendsController@isFriend')->name('api.friends.isFriend');
            //  修改好友昵称
            Route::post('update', 'Api\UserFriends\UserFriendsController@update')->name('api.friends.update');
            //搜索医生列表
            Route::get('searchDoctors', 'Api\UserFriends\UserFriendsController@searchDoctors');
        });

    });

    Route::group([
        'prefix' => 'manage',
    ], function () {
        // 回收上工返回的结果
        Route::match(['get', 'post'], 'reportReception', 'Manage\ImageTransmissionController@reportReception');
    });
});